package ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LENOVO
 * Date: 2024-08-02
 * Time: 15:07
 */
public class AddOperation implements Ioperation{
    @Override
    public void work(BookList bookList) {
        int currentPos = bookList.getUsedSize();
        if(currentPos == bookList.books.length){
            System.out.println("书架位置已满，插入失败！");
            return;
        }
        System.out.println("----新增图书-----");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入图书名称");
        String bookName = scanner.nextLine();
        System.out.println("请输入书籍作者");
        String bookAuthor = scanner.nextLine();
        System.out.println("请输入书籍价格");
        int bookPrice = scanner.nextInt();
        Book newBook = new Book(bookName,bookAuthor,bookPrice);
        bookList.setBook(newBook,currentPos);
        bookList.setUsedSize(currentPos + 1);
        System.out.println("《"+bookName+"》" + "增加成功！");
    }
}
